import type { RouteObject } from 'react-router-dom' //导入路由数据类型
import RouteTitle from './RouteTitle' //导入路由标题组件
import Layout from '@/layout/layout'

// system 系统管理
import Permission from '@/pages/system/permission/Permission' //导入权限管理页面
import Personinfo from '@/pages/system/personInfo/PersonInfo' //导入个人信息页面
import RoleManage from '@/pages/system/roleManage/RoleManage' //导入角色管理页面
import User from '@/pages/system/user/User' //导入用户页面
import UserManage from '@/pages/system/userManage/UserManage' //导入用户管理页面

// questions 试题管理
import AddQuestion from '@/pages/questions/addQuestion/AddQuestion' //导入添加试题页面
import Questions from '@/pages/questions/questionBank/QuestionBank' //导入试题库页面

// papers 试卷管理
import CreatePaper from '@/pages/papers/createPaper/CreatePaper' //导入创建试卷库页面
import ParperBank from '@/pages/papers/paperBank/PaperBank' //导入试卷库页面

// exam 考试管理
import CreateExam from '@/pages/exams/createExam/CreateExam' //导入创建考试页面
import ExamRecord from '@/pages/exams/examRecord/ExamRecord' //导入考试记录页面

// classes 班级管理
import ClassDetail from '@/pages/classes/classDetail/classDeatail' //导入班级详情页面
import ClassList from '@/pages/classes/classList/ClassList' //导入班级列表页面
import CreateClass from '@/pages/classes/createClass/Group-class' //导入创建班级页面
import StudentList from '@/pages/classes/studentList/StudentList' //导入学生列表页面

// 404
import NotFound from '@/pages/404/404' //导入404页面

// 登录 login
import Login from '@/pages/login/login' //导入登录页面




// 定义Router数据类型
type Router = RouteObject & { //&运算符用于合并多个类型
  title?: string
  layout?: boolean
}


// 路由配置
const routeConfig: Router[] = [
    { path: '/', layout:true, element: <RoleManage />, title: '首页，角色管理'},
    { path: '/permission', layout:true, element: <Permission /> , title: '权限管理' },
    { path: '/personinfo', layout:true, element: <Personinfo /> , title: '个人信息' },
    { path: '/user', layout:true, element: <User /> , title: '用户' },
    { path: '/userManage', layout:true, element: <UserManage /> , title: '用户管理' },

    { path: '/questions', layout:true, element: <Questions /> , title: '试题库' },
    { path: '/addQuestion', layout:true, element: <AddQuestion /> , title: '添加试题' },

    { path: '/papers', layout:true, element: <ParperBank /> , title: '试卷库' },
    { path: '/createPaper', layout:true, element: <CreatePaper /> , title: '创建试卷' },

    { path: '/exams', layout:true, element: <ExamRecord /> , title: '考试记录' },
    { path: '/createExam', layout:true, element: <CreateExam /> , title: '创建考试' },

    { path: '/classes', layout:true, element: <ClassList /> , title: '班级列表' },
    { path: '/classDetail', layout:true, element: <ClassDetail /> , title: '班级详情' },
    { path: '/createClass', layout:true, element: <CreateClass /> , title: '创建班级' },
    { path: '/studentList', layout:true, element: <StudentList /> , title: '学生列表' },


    { path: '/login', element: <Login /> , title: '登录' },
    { path: '/*', element: <NotFound /> , title: '404' }
]

// const Detail = React.lazy(() => import('../pages/detail/Detail'))


// // 转换路由数据接口，根据 isLogin 判断是否需要添加登陆拦截的组件
const formatRouteConfig = (routes: Router[]) => {
  return routes.map(item => {
    const route: RouteObject  = {
      path: item.path,
      element: <RouteTitle title={item.title}>{item.element}</RouteTitle>
    }
    if (item.layout) {
      route.element = <Layout>{route.element}</Layout>
    }
    return route
  })
}

export default formatRouteConfig(routeConfig)
